#include <iostream>
#include <string>

using namespace std;

// 复数类
class Complex
{
private:
	double real;
	double imag;

public:
	Complex()
		: real(0), imag(0)
	{
	}

	Complex(double real, double imag) : real(real), imag(imag)
	{
	}
	~Complex()
	{
	}

public:
	// 显示
	void Show()
	{
		cout << "实部" << real << "虚部" << imag << endl;
	}
	// 位操作 ! 的重载
	bool operator!()
	{
		bool b;
		b = !(this->imag + this->real);
		return b;
	}
	// 位操作运算符 <<的重载 必须写成全局函数
	friend ostream &operator<<(ostream &os, const Complex &o);
};

ostream &operator<<(ostream &os, const Complex &o)
{

	os << "实部" << o.real << "虚部" << o.imag;
	return os;
}

int main(int argc, char const *argv[])
{
	Complex F(10, 20);
	bool b = !F;
	/*当你写 cout << F << endl;它实际上等价于 (cout << F) << endl;
	如果 operator<< 返回的不是引用，
	(cout << c1) 的结果是一个新的 ostream 对象，
	后续的 << endl 将无法正确操作在原始的 cout 上。
	*/
	cout << F << endl;
	return 0;
}
